﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PingYou.Console
{
    class test
    {
        #region public void test() 历届测试方法
        /// <summary>
        /// 历届测试方法
        /// </summary>
        public void TestData()
        {
            #region 1. DataTable 行复制
            //DataTable myDt = new DataTable();
            //myDt.Columns.Add("ID", typeof(string));
            //myDt.Columns.Add("Name", typeof(string));
            //myDt.Columns.Add("CreateDate", typeof(DateTime));
            //myDt.Columns.Add("CreateStaff", typeof(string));

            //DataRow myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "1";
            //myNewDr["Name"] = "1名字";
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "1创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "2";
            //myNewDr["Name"] = "2名字";
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "2创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "3";
            //myNewDr["Name"] = "3名字";
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "3创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "4";
            //myNewDr["Name"] = "4名字";
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "4创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "5";
            //myNewDr["Name"] = "5名字";
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "5创建人";
            //myDt.Rows.Add(myNewDr);
            //myDt.AcceptChanges();

            //DataTable myCopyDt = myDt.Clone();
            //myNewDr = null;
            //for (int i = 0; i < 5; i++)
            //{
            //    myNewDr = myCopyDt.NewRow();
            //    myNewDr.ItemArray = myDt.Rows[i].ItemArray;
            //    myCopyDt.Rows.Add(myNewDr);
            //}
            #endregion

            #region 2. 时间格式化
            //string strDate = "23:00";
            //DateTime myDateTime = Convert.ToDateTime(strDate);
            ////当前日期下的23:00
            #endregion

            #region 3. double 取整数部分
            //为了防止double数据进行四舍五入，则将 原值-0.5， 结果获取的double类型的整数部分
            //double param_d_1 = 1.75;
            //int param_i_1 = Convert.ToInt16(param_d_1);
            //int param_i_2 = Convert.ToInt32(param_d_1);
            //double param_d_2 = param_d_1 - 0.5;
            //int param_i_3 = Convert.ToInt16(param_d_2);
            //int param_i_4 = Convert.ToInt32(param_d_2);
            //double param_d_3 = 2.0;
            //double param_d_4 = param_d_3 - 0.5;
            //int param_i_5 = Convert.ToInt16(param_d_4);
            //int param_i_6 = Convert.ToInt32(param_d_4);


            //double param_d_5 = 2.5;
            //double param_d_6 = param_d_5 - 0.5;
            //int param_i_7 = Convert.ToInt16(param_d_6);
            //int param_i_8 = Convert.ToInt32(param_d_6);

            //int result = 0;
            //int.TryParse(param_d_1.ToString(), out result);

            #endregion

            #region 4. datatable 排序  DataTable.Select(" XXX IN XXX");
            DataTable myDt = new DataTable();
            myDt.Columns.Add("ID", typeof(string));
            myDt.Columns.Add("index", typeof(int));
            myDt.Columns.Add("CreateDate", typeof(DateTime));
            myDt.Columns.Add("CreateStaff", typeof(string));

            DataRow myNewDr = myDt.NewRow();
            myNewDr["ID"] = "1";
            myNewDr["index"] = 1;
            myNewDr["CreateDate"] = DateTime.Now;
            myNewDr["CreateStaff"] = "1创建人";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "2";
            myNewDr["index"] = 3;
            myNewDr["CreateDate"] = DateTime.Now;
            myNewDr["CreateStaff"] = "2创建人";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "3";
            myNewDr["index"] = 2;
            myNewDr["CreateDate"] = DateTime.Now;
            myNewDr["CreateStaff"] = "3创建人";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "4";
            myNewDr["index"] = 2;
            myNewDr["CreateDate"] = DateTime.Now;
            myNewDr["CreateStaff"] = "4创建人";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "5";
            myNewDr["index"] = 78;
            myNewDr["CreateDate"] = DateTime.Now;
            myNewDr["CreateStaff"] = "5创建人";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "6";
            myNewDr["index"] = 78;
            myNewDr["CreateDate"] = DateTime.Now;
            myNewDr["CreateStaff"] = "6创建人";
            myDt.Rows.Add(myNewDr);

            myNewDr = myDt.NewRow();
            myNewDr["ID"] = "7";
            myNewDr["index"] = 81;
            myNewDr["CreateDate"] = DateTime.Now;
            myNewDr["CreateStaff"] = "7创建人";
            myDt.Rows.Add(myNewDr);
            myDt.AcceptChanges();

            //int i = 87;
            List<string> myList = new List<string> {
                "1", "5","4","3"
            };
            string whereStr = string.Empty;
            foreach (string str in myList)
            {
                whereStr += "," + str;
            }
            myDt.Select(string.Format("{0} in ({1})", "ID", whereStr.Substring(1)));

            DataTable myCopyDt = myDt.Clone();
            myNewDr = null;


            #endregion

            #region
            string ids = string.Empty;
            DataTable myIdDt = new DataTable();
            myIdDt.Columns.AddRange(new DataColumn[] { 
            new DataColumn("ID"),
            new DataColumn("FullName")
            });
            myNewDr = myIdDt.NewRow();
            myNewDr["ID"] = "10000001";
            myIdDt.Rows.Add(myNewDr);

            myNewDr = myIdDt.NewRow();
            myNewDr["ID"] = "10000002";
            myIdDt.Rows.Add(myNewDr);

            myNewDr = myIdDt.NewRow();
            myNewDr["ID"] = "10000003";
            myIdDt.Rows.Add(myNewDr);

            ids = string.Join("','", from c in myIdDt.AsEnumerable()
                                     select c["ID"]);

            if (ids.Length > 0)
            {
                ids = "'" + ids + "'";
            }


            #endregion

            #region 匹配科目 选课报表
            DataTable myStudentCourseDt = new DataTable();
            //年级
            DataTable ColCourseDt = new DataTable();
            myStudentCourseDt.Columns.AddRange(new DataColumn[] { 
                new DataColumn("StudentBaseID"),
                new DataColumn("PublicCourseID"),
                new DataColumn("CourseName")
            });

            foreach (DataRow myDr in ColCourseDt.Rows)
            {
                string[] myArr = myDr["PublicCourseIDs"].ToString().Split(',');
                DataRow[] myPublicCourseDrs = myStudentCourseDt.Select(string.Format("PublicCourseID=" + myArr[0].ToString()));
                if (myPublicCourseDrs.Length > 0)
                {
                    myPublicCourseDrs.CopyToDataTable().Select(string.Format("PublicCourseID=" + myArr[1].ToString()));
                }
            }
            #endregion

            #region 3. double 取整数部分
            //为了防止double数据进行四舍五入，则将 原值-0.5， 结果获取的double类型的整数部分
            //double param_d_1 = 1.75;
            //int param_i_1 = Convert.ToInt16(param_d_1);
            //int param_i_2 = Convert.ToInt32(param_d_1);
            //double param_d_2 = param_d_1 - 0.5;
            //int param_i_3 = Convert.ToInt16(param_d_2);
            //int param_i_4 = Convert.ToInt32(param_d_2);
            //double param_d_3 = 2.0;
            //double param_d_4 = param_d_3 - 0.5;
            //int param_i_5 = Convert.ToInt16(param_d_4);
            //int param_i_6 = Convert.ToInt32(param_d_4);


            //double param_d_5 = 2.5;
            //double param_d_6 = param_d_5 - 0.5;
            //int param_i_7 = Convert.ToInt16(param_d_6);
            //int param_i_8 = Convert.ToInt32(param_d_6);

            //int result = 0;
            //int.TryParse(param_d_1.ToString(), out result);

            #endregion

            #region 4. datatable 排序  DataTable.Select(" XXX IN XXX");
            //DataTable myDt = new DataTable();
            //myDt.Columns.Add("ID", typeof(string));
            //myDt.Columns.Add("index", typeof(int));
            //myDt.Columns.Add("CreateDate", typeof(DateTime));
            //myDt.Columns.Add("CreateStaff", typeof(string));

            //DataRow myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "1";
            //myNewDr["index"] = 1;
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "1创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "2";
            //myNewDr["index"] = 3;
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "2创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "3";
            //myNewDr["index"] = 2;
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "3创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "4";
            //myNewDr["index"] = 2;
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "4创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "5";
            //myNewDr["index"] = 78;
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "5创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "6";
            //myNewDr["index"] = 78;
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "6创建人";
            //myDt.Rows.Add(myNewDr);

            //myNewDr = myDt.NewRow();
            //myNewDr["ID"] = "7";
            //myNewDr["index"] = 81;
            //myNewDr["CreateDate"] = DateTime.Now;
            //myNewDr["CreateStaff"] = "7创建人";
            //myDt.Rows.Add(myNewDr);
            //myDt.AcceptChanges();

            //int i = 87;
            //List<string> myList = new List<string> {
            //    "1", "5","4","3"
            //};
            //string whereStr = string.Empty;
            //foreach (string str in myList)
            //{
            //    whereStr += "," + str;
            //}
            //myDt.Select(string.Format("{0} in ({1})", "ID", whereStr.Substring(1)));

            //DataTable myCopyDt = myDt.Clone();
            //myNewDr = null;

            #endregion

            //new ExecProcess().GetUrlTrans();

            //#endregion

            //#region
            //string ids = string.Empty;
            //DataTable myIdDt = new DataTable();
            //myIdDt.Columns.AddRange(new DataColumn[] { 
            //new DataColumn("ID"),
            //new DataColumn("FullName")
            //});
            //myNewDr = myIdDt.NewRow();
            //myNewDr["ID"] = "10000001";
            //myIdDt.Rows.Add(myNewDr);

            //myNewDr = myIdDt.NewRow();
            //myNewDr["ID"] = "10000002";
            //myIdDt.Rows.Add(myNewDr);

            //myNewDr = myIdDt.NewRow();
            //myNewDr["ID"] = "10000003";
            //myIdDt.Rows.Add(myNewDr);

            //ids = string.Join("','", from c in myIdDt.AsEnumerable()
            //                         select c["ID"]);

            //if (ids.Length > 0)
            //{
            //    ids = "'" + ids + "'";
            //}


            //#endregion

            //#region 匹配科目 选课报表
            //DataTable myStudentCourseDt = new DataTable();
            ////年级
            //DataTable ColCourseDt = new DataTable();
            //myStudentCourseDt.Columns.AddRange(new DataColumn[] { 
            //    new DataColumn("StudentBaseID"),
            //    new DataColumn("PublicCourseID"),
            //    new DataColumn("CourseName")
            //});

            //foreach (DataRow myDr in ColCourseDt.Rows)
            //{
            //    string[] myArr = myDr["PublicCourseIDs"].ToString().Split(',');
            //    DataRow[] myPublicCourseDrs = myStudentCourseDt.Select(string.Format("PublicCourseID=" + myArr[0].ToString()));
            //    if (myPublicCourseDrs.Length > 0)
            //    {
            //        myPublicCourseDrs.CopyToDataTable().Select(string.Format("PublicCourseID=" + myArr[1].ToString()));
            //    }
            //}
            //#endregion


        }
        #endregion
    }
}
